using AutoMapper;
using Domain.Repositories;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using SDK.Vo;

namespace WebApi.SdkControllers;

/// <summary>
/// SDK 相关
/// </summary>
[Route("sdk/api/[controller]")]
[ApiController]
public class UserSdkController: ControllerBase
{
    private readonly IUserRepository _userRepository;
    private readonly IMapper _mapper;
    private readonly IMediator _mediator;
    
    /// <summary>
    /// 用户
    /// </summary>
    /// <param name="userRepository"></param>
    /// <param name="mapper"></param>
    /// <param name="mediator"></param>
    public UserSdkController(IUserRepository userRepository, IMapper mapper, IMediator mediator)
    {
        _userRepository = userRepository;
        _mapper = mapper;
        _mediator = mediator;
    }
    
    /// <summary>
    /// 用户详情
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpGet("{id}")]
    public async Task<UserVo> GetUser(long id)
    {
        var user = await _userRepository.GetAsync(u=>u.Id==id);

        return _mapper.Map<UserVo>(user);
    }
}